import os
from configparser import ConfigParser


class Config:
    def __init__(self, conf_dirpath, conf_filename):
        self.conf_dirpath = conf_dirpath
        self.conf_filename = conf_filename

    def get_config(self):
        # 获取当前文件的目录
        basedir = os.path.abspath(os.path.dirname(__file__))
        parent_dir = os.path.dirname(basedir)

        # 构建datasource.conf的路径
        config_path = os.path.join(parent_dir, self.conf_dirpath, self.conf_filename)
        # print(config_path)
        # 创建ConfigParser对象
        config = ConfigParser()

        # 读取配置文件
        config.read(config_path)
        return config



# if __name__ == "__main__":
#     c = Config("config", "project_info.conf")
#     conf = c.get_config()
#     print(conf.get("datasource","host"))